package Tree;

import org.junit.Test;

/**
 * @author yyq
 * @create 2021-10-27 13:27
 */
public class TreeTest {
    @Test
    public void _preOrder(){
        TreeNode root=new TreeNode(1);
        root.left=new TreeNode(2);
        root.right=new TreeNode(3);
        root.left.left=new TreeNode(4);
        root.right.right=new TreeNode(5);
        BinaryTree.preOrder(root);
    }
    @Test
    public void _infixOrder(){
        TreeNode root=new TreeNode(1);
        root.left=new TreeNode(2);
        root.right=new TreeNode(3);
        root.left.left=new TreeNode(4);
        root.right.right=new TreeNode(5);
        BinaryTree.inFixOrder(root);
    }
    @Test
    public void _postOrder(){
        TreeNode root=new TreeNode(1);
        root.left=new TreeNode(2);
        root.right=new TreeNode(3);
        root.left.left=new TreeNode(4);
        root.right.right=new TreeNode(5);
        BinaryTree.postOrder(root);
    }

    @Test
    public void _preFind(){
        TreeNode<Employee> root=new TreeNode(new Employee(1,"杨云卿"));
        root.left=new TreeNode(new Employee(2,"李瑞"));
        root.right=new TreeNode(new Employee(3,"侯柳洲"));
        root.left.left=new TreeNode(new Employee(4,"孙怀菊"));
        root.right.right=new TreeNode(new Employee(5,"杨洪"));
        Employee employee = BinaryTree.preFind(5, root);
        if(employee==null) System.out.println("抱歉未找到");
        else System.out.println(employee);
    }
    @Test
    public void _infixFind(){
        TreeNode<Employee> root=new TreeNode(new Employee(1,"杨云卿"));
        root.left=new TreeNode(new Employee(2,"李瑞"));
        root.right=new TreeNode(new Employee(3,"侯柳洲"));
        root.left.left=new TreeNode(new Employee(4,"孙怀菊"));
        root.right.right=new TreeNode(new Employee(5,"杨洪"));
        Employee employee = BinaryTree.infixFind(1, root);
        if(employee==null) System.out.println("抱歉未找到");
        else System.out.println(employee);
    }

    @Test
    public void _preDelOrder(){
        TreeNode root=new TreeNode(1);
        root.left=new TreeNode(2);
        root.right=new TreeNode(3);
        root.left.left=new TreeNode(4);
        root.right.right=new TreeNode(5);
        BinaryTree.preOrder(root);
        System.out.println("****");
        Boolean flag = BinaryTree.deleteNode(root, null,null,2);
        if(flag) System.out.println("删除成功");
        else System.out.println("删除失败");
        BinaryTree.preOrder(root);
    }
}
